package androidx.fragment.app;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import androidx.activity.ComponentActivity;
import androidx.activity.OnBackPressedDispatcher;
import androidx.activity.c;
import androidx.core.app.a;
import androidx.lifecycle.e;
import androidx.lifecycle.i;
import androidx.lifecycle.u;
import androidx.lifecycle.v;
import b.d.h;
import java.io.FileDescriptor;
import java.io.PrintWriter;

public class d extends ComponentActivity implements a.b, a.d {
    final h h = h.b(new a());
    final i i = new i(this);
    boolean j;
    boolean k;
    boolean l = true;
    boolean m;
    boolean n;
    boolean o;
    int p;
    h<String> q;

    class a extends j<d> implements v, c {
        public a() {
            super(d.this);
        }

        public OnBackPressedDispatcher b() {
            return d.this.b();
        }

        public View c(int i) {
            return d.this.findViewById(i);
        }

        public boolean d() {
            Window window = d.this.getWindow();
            return (window == null || window.peekDecorView() == null) ? false : true;
        }

        public e getLifecycle() {
            return d.this.i;
        }

        public u getViewModelStore() {
            return d.this.getViewModelStore();
        }

        public void h(Fragment fragment) {
            d.this.p(fragment);
        }

        public LayoutInflater j() {
            return d.this.getLayoutInflater().cloneInContext(d.this);
        }

        public void k(Fragment fragment, String[] strArr, int i) {
            d.this.s(fragment, strArr, i);
        }

        public boolean l(Fragment fragment) {
            return !d.this.isFinishing();
        }

        public boolean m(String str) {
            return androidx.core.app.a.j(d.this, str);
        }

        public void n(Fragment fragment, Intent intent, int i, Bundle bundle) {
            d.this.t(fragment, intent, i, bundle);
        }

        public void o(Fragment fragment, IntentSender intentSender, int i, Intent intent, int i2, int i3, int i4, Bundle bundle) {
            d.this.u(fragment, intentSender, i, intent, i2, i3, i4, bundle);
        }

        public void p() {
            d.this.v();
        }

        /* renamed from: q */
        public d i() {
            return d.this;
        }
    }

    private int j(Fragment fragment) {
        if (this.q.l() < 65534) {
            while (this.q.g(this.p) >= 0) {
                this.p = (this.p + 1) % 65534;
            }
            int i2 = this.p;
            this.q.j(i2, fragment.mWho);
            this.p = (this.p + 1) % 65534;
            return i2;
        }
        throw new IllegalStateException("Too many pending Fragment activity results.");
    }

    static void k(int i2) {
        if ((i2 & -65536) != 0) {
            throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");
        }
    }

    private void n() {
        do {
        } while (o(m(), e.b.CREATED));
    }

    private static boolean o(m mVar, e.b bVar) {
        boolean z = false;
        for (Fragment next : mVar.f0()) {
            if (next != null) {
                if (next.getHost() != null) {
                    z |= o(next.getChildFragmentManager(), bVar);
                }
                if (next.getLifecycle().b().a(e.b.STARTED)) {
                    next.mLifecycleRegistry.p(bVar);
                    z = true;
                }
            }
        }
        return z;
    }

    public final void a(int i2) {
        if (!this.m && i2 != -1) {
            k(i2);
        }
    }

    public void dump(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
        super.dump(str, fileDescriptor, printWriter, strArr);
        printWriter.print(str);
        printWriter.print("Local FragmentActivity ");
        printWriter.print(Integer.toHexString(System.identityHashCode(this)));
        printWriter.println(" State:");
        String str2 = str + "  ";
        printWriter.print(str2);
        printWriter.print("mCreated=");
        printWriter.print(this.j);
        printWriter.print(" mResumed=");
        printWriter.print(this.k);
        printWriter.print(" mStopped=");
        printWriter.print(this.l);
        if (getApplication() != null) {
            b.k.a.a.b(this).a(str2, fileDescriptor, printWriter, strArr);
        }
        this.h.u().M(str, fileDescriptor, printWriter, strArr);
    }

    /* access modifiers changed from: package-private */
    public final View l(View view, String str, Context context, AttributeSet attributeSet) {
        return this.h.w(view, str, context, attributeSet);
    }

    public m m() {
        return this.h.u();
    }

    /* access modifiers changed from: protected */
    public void onActivityResult(int i2, int i3, Intent intent) {
        this.h.v();
        int i4 = i2 >> 16;
        if (i4 != 0) {
            int i5 = i4 - 1;
            String e = this.q.e(i5);
            this.q.k(i5);
            if (e == null) {
                Log.w("FragmentActivity", "Activity result delivered for unknown Fragment.");
                return;
            }
            Fragment t = this.h.t(e);
            if (t == null) {
                Log.w("FragmentActivity", "Activity result no fragment exists for who: " + e);
                return;
            }
            t.onActivityResult(i2 & 65535, i3, intent);
            return;
        }
        a.c g = androidx.core.app.a.g();
        if (g == null || !g.b(this, i2, i3, intent)) {
            super.onActivityResult(i2, i3, intent);
        }
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        this.h.v();
        this.h.d(configuration);
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        this.h.a((Fragment) null);
        if (bundle != null) {
            this.h.x(bundle.getParcelable("android:support:fragments"));
            if (bundle.containsKey("android:support:next_request_index")) {
                this.p = bundle.getInt("android:support:next_request_index");
                int[] intArray = bundle.getIntArray("android:support:request_indicies");
                String[] stringArray = bundle.getStringArray("android:support:request_fragment_who");
                if (intArray == null || stringArray == null || intArray.length != stringArray.length) {
                    Log.w("FragmentActivity", "Invalid requestCode mapping in savedInstanceState.");
                } else {
                    this.q = new h<>(intArray.length);
                    for (int i2 = 0; i2 < intArray.length; i2++) {
                        this.q.j(intArray[i2], stringArray[i2]);
                    }
                }
            }
        }
        if (this.q == null) {
            this.q = new h<>();
            this.p = 0;
        }
        super.onCreate(bundle);
        this.i.i(e.a.ON_CREATE);
        this.h.f();
    }

    public boolean onCreatePanelMenu(int i2, Menu menu) {
        return i2 == 0 ? super.onCreatePanelMenu(i2, menu) | this.h.g(menu, getMenuInflater()) : super.onCreatePanelMenu(i2, menu);
    }

    public View onCreateView(View view, String str, Context context, AttributeSet attributeSet) {
        View l2 = l(view, str, context, attributeSet);
        return l2 == null ? super.onCreateView(view, str, context, attributeSet) : l2;
    }

    public View onCreateView(String str, Context context, AttributeSet attributeSet) {
        View l2 = l((View) null, str, context, attributeSet);
        return l2 == null ? super.onCreateView(str, context, attributeSet) : l2;
    }

    /* access modifiers changed from: protected */
    public void onDestroy() {
        super.onDestroy();
        this.h.h();
        this.i.i(e.a.ON_DESTROY);
    }

    public void onLowMemory() {
        super.onLowMemory();
        this.h.i();
    }

    public boolean onMenuItemSelected(int i2, MenuItem menuItem) {
        if (super.onMenuItemSelected(i2, menuItem)) {
            return true;
        }
        if (i2 == 0) {
            return this.h.k(menuItem);
        }
        if (i2 != 6) {
            return false;
        }
        return this.h.e(menuItem);
    }

    public void onMultiWindowModeChanged(boolean z) {
        this.h.j(z);
    }

    /* access modifiers changed from: protected */
    public void onNewIntent(@SuppressLint({"UnknownNullness"}) Intent intent) {
        super.onNewIntent(intent);
        this.h.v();
    }

    public void onPanelClosed(int i2, Menu menu) {
        if (i2 == 0) {
            this.h.l(menu);
        }
        super.onPanelClosed(i2, menu);
    }

    /* access modifiers changed from: protected */
    public void onPause() {
        super.onPause();
        this.k = false;
        this.h.m();
        this.i.i(e.a.ON_PAUSE);
    }

    public void onPictureInPictureModeChanged(boolean z) {
        this.h.n(z);
    }

    /* access modifiers changed from: protected */
    public void onPostResume() {
        super.onPostResume();
        r();
    }

    public boolean onPreparePanel(int i2, View view, Menu menu) {
        return i2 == 0 ? q(view, menu) | this.h.o(menu) : super.onPreparePanel(i2, view, menu);
    }

    public void onRequestPermissionsResult(int i2, String[] strArr, int[] iArr) {
        this.h.v();
        int i3 = (i2 >> 16) & 65535;
        if (i3 != 0) {
            int i4 = i3 - 1;
            String e = this.q.e(i4);
            this.q.k(i4);
            if (e == null) {
                Log.w("FragmentActivity", "Activity result delivered for unknown Fragment.");
                return;
            }
            Fragment t = this.h.t(e);
            if (t == null) {
                Log.w("FragmentActivity", "Activity result no fragment exists for who: " + e);
                return;
            }
            t.onRequestPermissionsResult(i2 & 65535, strArr, iArr);
        }
    }

    /* access modifiers changed from: protected */
    public void onResume() {
        super.onResume();
        this.k = true;
        this.h.v();
        this.h.s();
    }

    /* access modifiers changed from: protected */
    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        n();
        this.i.i(e.a.ON_STOP);
        Parcelable y = this.h.y();
        if (y != null) {
            bundle.putParcelable("android:support:fragments", y);
        }
        if (this.q.l() > 0) {
            bundle.putInt("android:support:next_request_index", this.p);
            int[] iArr = new int[this.q.l()];
            String[] strArr = new String[this.q.l()];
            for (int i2 = 0; i2 < this.q.l(); i2++) {
                iArr[i2] = this.q.i(i2);
                strArr[i2] = this.q.m(i2);
            }
            bundle.putIntArray("android:support:request_indicies", iArr);
            bundle.putStringArray("android:support:request_fragment_who", strArr);
        }
    }

    /* access modifiers changed from: protected */
    public void onStart() {
        super.onStart();
        this.l = false;
        if (!this.j) {
            this.j = true;
            this.h.c();
        }
        this.h.v();
        this.h.s();
        this.i.i(e.a.ON_START);
        this.h.q();
    }

    public void onStateNotSaved() {
        this.h.v();
    }

    /* access modifiers changed from: protected */
    public void onStop() {
        super.onStop();
        this.l = true;
        n();
        this.h.r();
        this.i.i(e.a.ON_STOP);
    }

    public void p(Fragment fragment) {
    }

    /* access modifiers changed from: protected */
    @Deprecated
    public boolean q(View view, Menu menu) {
        return super.onPreparePanel(0, view, menu);
    }

    /* access modifiers changed from: protected */
    public void r() {
        this.i.i(e.a.ON_RESUME);
        this.h.p();
    }

    /* JADX INFO: finally extract failed */
    /* access modifiers changed from: package-private */
    public void s(Fragment fragment, String[] strArr, int i2) {
        if (i2 == -1) {
            androidx.core.app.a.i(this, strArr, i2);
            return;
        }
        k(i2);
        try {
            this.m = true;
            androidx.core.app.a.i(this, strArr, ((j(fragment) + 1) << 16) + (i2 & 65535));
            this.m = false;
        } catch (Throwable th) {
            this.m = false;
            throw th;
        }
    }

    public void startActivityForResult(@SuppressLint({"UnknownNullness"}) Intent intent, int i2) {
        if (!this.o && i2 != -1) {
            k(i2);
        }
        super.startActivityForResult(intent, i2);
    }

    public void startActivityForResult(@SuppressLint({"UnknownNullness"}) Intent intent, int i2, Bundle bundle) {
        if (!this.o && i2 != -1) {
            k(i2);
        }
        super.startActivityForResult(intent, i2, bundle);
    }

    public void startIntentSenderForResult(@SuppressLint({"UnknownNullness"}) IntentSender intentSender, int i2, Intent intent, int i3, int i4, int i5) {
        if (!this.n && i2 != -1) {
            k(i2);
        }
        super.startIntentSenderForResult(intentSender, i2, intent, i3, i4, i5);
    }

    public void startIntentSenderForResult(@SuppressLint({"UnknownNullness"}) IntentSender intentSender, int i2, Intent intent, int i3, int i4, int i5, Bundle bundle) {
        if (!this.n && i2 != -1) {
            k(i2);
        }
        super.startIntentSenderForResult(intentSender, i2, intent, i3, i4, i5, bundle);
    }

    public void t(Fragment fragment, @SuppressLint({"UnknownNullness"}) Intent intent, int i2, Bundle bundle) {
        this.o = true;
        if (i2 == -1) {
            try {
                androidx.core.app.a.k(this, intent, -1, bundle);
            } finally {
                this.o = false;
            }
        } else {
            k(i2);
            androidx.core.app.a.k(this, intent, ((j(fragment) + 1) << 16) + (i2 & 65535), bundle);
            this.o = false;
        }
    }

    public void u(Fragment fragment, @SuppressLint({"UnknownNullness"}) IntentSender intentSender, int i2, Intent intent, int i3, int i4, int i5, Bundle bundle) {
        int i6 = i2;
        this.n = true;
        if (i6 == -1) {
            try {
                androidx.core.app.a.l(this, intentSender, i2, intent, i3, i4, i5, bundle);
            } finally {
                this.n = false;
            }
        } else {
            k(i2);
            androidx.core.app.a.l(this, intentSender, ((j(fragment) + 1) << 16) + (i6 & 65535), intent, i3, i4, i5, bundle);
            this.n = false;
        }
    }

    @Deprecated
    public void v() {
        invalidateOptionsMenu();
    }
}
